层次违例(Hierarchy violation)
简介
SpinalHDL将会检查当前层次设计的信号不会访问到该组件的外部区域。
以下信号可以在组件内部读取:
- 当前组件中定义的所有无方向信号 
- 当前组件的所有in/out/inout信号 
- 子组件的所有in/out/inout信号 
同时,以下信号可以在组件内部赋值:
- 当前组件中定义的所有无方向信号 
- 当前组件的所有out/inout信号 
- 子组件的所有in/inout信号 
如果出现 HIERARCHY VIOLATION 错误,则意味着违反了上述规则之一。
示例
下面的代码:
class TopLevel extends Component {
  val io = new Bundle {
    // This is an 'in' signal of the current component 'Toplevel'
    val a = in UInt(8 bits)
  }
  val tmp = U"x42"
  io.a := tmp  // ERROR: attempting to assign to an input of current component
}
会报错:
HIERARCHY VIOLATION : (toplevel/io_a : in UInt[8 bits]) is driven by (toplevel/tmp :  UInt[8 bits]), but isn't accessible in the toplevel component.
  ***
  Source file location of the `io.a := tmp` via the stack trace
  ***
一个可能的修复方法是:
class TopLevel extends Component {
  val io = new Bundle {
    val a = out UInt(8 bits) // changed from in to out
  }
  val tmp = U"x42"
  io.a := tmp  // now we are assigning to an output
}